﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IdeaNMR.Shared;

namespace IdeaNMR.Web.Core
{
    public enum EntityType : int
    {
        PulseProgram = 0,
        WaveShape,
        Cpd,
        Script,
        Sample,
        Spectrometer
    }

    public static class EntityTypeExtensions
    {
        public static string ToCategoryName(this EntityType eT)
        {
            switch (eT)
            {
                case EntityType.PulseProgram:
                    //return "S/N Prediction";
                    return "Pulse Program";
                case EntityType.WaveShape:
                    return "Wave Shape";
                case EntityType.Cpd:
                    return "CPD Scheme";
                case EntityType.Script:
                    return "Script";
                case EntityType.Sample:
                    return "Sample";
                case EntityType.Spectrometer:
                    return "Spectrometer";
                default:
                    throw new NotImplementedException("EntityType " + eT.ToString() + " is not supported in ToCategoryName extension method.");
            }
        }

        /// <summary>
        /// Converts <see cref="IdeaNMR.Web.Core.EntityType"/> to <see cref="IdeaNMR.Shared.ComponentType"/>
        /// </summary>
        /// <param name="eT"></param>
        /// <returns><see cref="IdeaNMR.Shared.ComponentType"/> value corresponding to <paramref name="eT"/>.</returns>
        /// <exception cref="System.ArgumentOutOfRangeException">thrown when <paramref name="eT"/> is Spectrometer or Sample.</exception>
        public static ComponentType ToComponentType(this EntityType eT)
        {
            ComponentType result;
            bool converted = Enum.TryParse<ComponentType>(eT.ToString(), out result);

            if (converted) return result;
            string err = string.Format("Parameter eT must be PulseProgram, WaveShape, Cpd or Script. Here it's {0}", eT.ToString());
            throw new ArgumentOutOfRangeException("eT", err);
        }
    }
}
